<form id="form">
<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal">
		<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
	</button>
	<small class="modal-title">
	<#if model??>
		<i class="fa fa-pencil"></i> 编辑	
	<#else>
		<i class="fa fa-plus"></i> 新增
	</#if>
	</small>
</div>
<div class="modal-body" style="height:330px;overflow-y:auto;">
	<div class="tabs-container">
		<div class="form-horizontal clearfix">
			<input type="hidden" name="id" value="<#if model??>${model.id!''}</#if>"/>
			<div class="col-sm-12">
				<div class="form-group">
					<label class="col-sm-3 control-label">公众号名称：</label>
					<div class="col-sm-8 input-group">
						<input name="name" type="text" placeholder="请输入公众号名称"
							class="form-control requiredIcon" value="<#if model??>${model.name!''}</#if>">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">公众号原始id：</label>
					<div class="col-sm-8 input-group">
						<input name="originid" type="text" placeholder="请输入公众号原始id"
							class="form-control requiredIcon" value="<#if model??>${model.originid!''}</#if>">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">微信号：</label>
					<div class="col-sm-8 input-group">
						<input name="number" type="text" placeholder="请输入微信号"
							class="form-control requiredIcon" value="<#if model??>${model.number!''}</#if>">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">AppID（公众号）：</label>
					<div class="col-sm-8 input-group">
						<input name="appid" type="text" placeholder="请输入AppID"
							class="form-control requiredIcon" value="<#if model??>${model.appid!''}</#if>">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">AppSecret：</label>
					<div class="col-sm-8 input-group">
						<input name="appsecret" type="text" placeholder="请输入AppSecret"
							class="form-control requiredIcon" value="<#if model??>${model.appsecret!''}</#if>">
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="modal-footer">
	<button class="btn btn-white" data-dismiss="modal">关闭</button>
	<button class="btn btn-primary" type="submit">保存</button>
</div>
</form>
<script>
	$(function(){
        var validator = $("#form").validate({
      	  rules: {
                name: {
                    required: true
                },
                originid: {
                    required: true
                },
                number: {
                    required: true
                },
                appid: {
                    required: true
                },
                appsecret: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: icon + "请输入公众号名称"
                },
                originid: {
                    required: icon + "请输入公众号原始id"
                },
                number: {
                    required: icon + "请输入微信号"
                },
                appid: {
                    required: icon + "请输入AppID"
                },
                appsecret: {
                    required: icon + "请输入AppSecret"
                }
            },
            submitHandler: function(form){
            	var id = $("#form input[name=id]").val();
            	$(form).ajaxSubmit({
               		url:"${basePath}/wxuser/" + (id == "" ? "add" : "edit") ,
               	 	type:"POST",
               	 	dataType:"json",
               	 	success: function (resp) {
	               	 	if(resp.code == 0) {
	               	 		$("#formModal").modal("hide");
	                    	$("#table").bootstrapTable("refresh");
	                    	toastr.success("操作成功.","");
	                    }else if(resp.code == 1){
	                    	toastr.error("操作失败.","");
	                    }else {
	                    	toastr.error(resp.data, "");
	                    }
                 	}
                });    
            },
            showErrors: function(errorMap, errorList) {
          		this.defaultShowErrors();
          }
        });		
	})
</script>

